package utils;

import java.util.ArrayList;
import java.util.List;

import pojo.*;

/**
 * 搜索引擎
 * @author Arthas
 * 
 */
public class APage {

	 /**
	  * 新闻的集合分页实现
	  * @param currentPage 当前页码
	  * @param pageSize 每页显示的条数
	  * @param list  所有集合
	  * @throws Exception
	  */
	public static List<News> collSetPagingPojo(int currentPage, int pageSize, List<News> list) {
		List<News> result = new ArrayList<News>();
		if (list != null && list.size() > 0) {
			int allCount = list.size();
			int pageCount = (allCount + pageSize - 1) / pageSize;
			if (currentPage >= pageCount) {
				currentPage = pageCount;
			}
			int start = (currentPage - 1) * pageSize;
			int end = currentPage * pageSize;
			if (end >= allCount) {
				end = allCount;
			}
			for (int i = start; i < end; i++) {
				result.add(list.get(i));
			}
		}
		return (result != null && result.size() > 0) ? result : null;
	}


}
